﻿using nplJobsCommon.Common;
using nplJobsCommon.Job;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Insert
{
    public class InsertJobApplicationProcedure : DataAccessBase
    {
        public int lastJobApplicationProcedureID = 0;
        public JobApplicationProcedure JobApplicationProcedure { get; set; }

        public InsertJobApplicationProcedure()
        {
            StoredProcedureName = StoredProcedure.Name.spInsertJobApplicationProcedure.ToString();
        }

        public void Insert()
        {
            InsertJobApplicationProcedureDataParameters insertJobApplicationDataParameters = new InsertJobApplicationProcedureDataParameters(this.JobApplicationProcedure);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = insertJobApplicationDataParameters.Parameters;
            object lastJobApplicationProcedureID = dbHelper.RunScalar();


            if (lastJobApplicationProcedureID != null)
            {
                this.lastJobApplicationProcedureID = int.Parse(lastJobApplicationProcedureID.ToString());

            }
            //if (insertEmployeerDataParameters.Parameters[24].Value != null)
            //{
            //    lastJobID = insertEmployeerDataParameters.Parameters[24].Value.ToString();
            //}
        }
    }

    #region SQL parameters for job application procedure entry
    public class InsertJobApplicationProcedureDataParameters
    {
        public int lastJobApplicationProcedureID;
        private SqlParameter[] _parameters;

        public InsertJobApplicationProcedureDataParameters(JobApplicationProcedure jobapplicationprocedure)
        {
            this.JobApplicationProcedure = jobapplicationprocedure;
            Build();
        }

        #region spAddContact parameters
        /*
         
         */
        #endregion

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@JobID", JobApplicationProcedure.JobID),
                    new SqlParameter("@ApplicationProcedureID", JobApplicationProcedure.ApplicationProcedureID),
                };
            Parameters = parameters;
        }

        public JobApplicationProcedure JobApplicationProcedure { get; set; }

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }
    }
    #endregion
}

